function canImgToAscii(imgCan,printDiv){
 var c=document.getElementById(imgCan);
  var W=c.width; 
  var H=c.height;   
  var character, line = "";
  var pixels = document.getElementById(imgCan).getContext('2d').getImageData(0, 0, W, H);
	var colordata = pixels.data;
	var piDiv=document.getElementById(printDiv);
	var imgStr="<pre style='font-size:x-small;margin:0px;line-height:60%;width:960px;height:714px;'>";
	for(var i = 0; i < colordata.length; i = i+4){
	var	r = colordata[i];
	var	g = colordata[i+1];
	var	b = colordata[i+2];
		//converting the pixel into grayscale
	var	gray = r*0.3333 + g*0.3333 + b*0.3333;

		if(gray > 250) character = " "; 
		else if(gray > 230) character = "`";
		else if(gray > 200) character = ":";
		else if(gray > 175) character = "*";
		else if(gray > 150) character = "+";
		else if(gray > 130) character = "&";
		else if(gray > 125) character = "#";
		else if(gray > 50) character = "W";
		else character = "@";
		if(i != 0 && (i/4)%W == 0)
		{
		   imgStr+=line;
		   imgStr+="<br>";
		   line = "";
		}
		
		line += character;
	}
	imgStr+="</pre>";
  piDiv.innerHTML=imgStr;
}